<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="../function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加新闻</title>
    <link  href="../../images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../../css/messages_doctor_mes_add.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../../css/sweetalert.css?cache=<%=Math.random()%>" >
    <script src="../../js/jquery-1.9.1.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="/css/editor/summernote.css" rel="stylesheet">
    <script src="/css/editor/summernote.js"></script>
    </head>
<body>
    <%@ include file="../../header.jsp"%>
    <!--内容-->
    <div class="containerone">
    <%@ include file="../../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
    <!--右边内容-->
    <!--右边内容-->
    <div class="message_right_cont_box" id="add_news">
      <div>
          <div class="message_right_cont_container">
    <div class="add_doctor_tittle"><span v-html="deptName"></span>/<span v-html="option"></span></div>
              <div class="add_doctor">
                  <span>添加新闻</span>
                  <a href="javascript:void(0);"><button class="back_doctor_mes" @click="back()">返回</button></a>
              </div>
              <%--编辑新闻开始--%>
                <input type="hidden" name="act" value="add"/>
                <input type="hidden" name="deptCode" value=""/>
                <input type="hidden" name="labelId" value=""/>
                <%--编辑新闻开始--%>
                 <div class="news_eidt_title"><span>新闻标题:</span><input class="news_add_tittle" name="title" v-model="title"  type="text" required >
                   <%--<p class="news_title_tip">新闻标题不能为空</p>--%>
                    <div class="clearfix"></div>
                 </div>
                 <div class="news_eidt_title"><span>作者:</span><input class="news_add_author" name="author" type="text"  v-model="author">
                  <%--<p class="news_author_tip">作者不能为空</p>--%>
                    <div class="clearfix"></div>
                 </div>
                 <div class='doc_good_at'>
                    <div class='doc_good_at_tip'><span>新闻简介:</span>(限输入200字符)</div>
                    <div class='doc_good_at_textarea'>
                       <textarea name="summary" id="" v-model="summary" style="width:900px;height:100px;"  maxlength="200"  class="news_add_summary"></textarea>
                    </div>
                 </div>
            <%--<p class="news_summary_tip">请输入新闻简介</p>--%>
              <div class='doc_good_at'>
              <div class='doc_good_at_tip'><span>新闻内容:</span></div>
              <div style="width:900px;">
              <div id="editor" ></div>
              </div>
              <%--<p class="news_content_tip">请输入新闻内容</p>--%>
              </div>
    <%--编辑新闻结束--%>
    <%--医生编辑取消和确定开始--%>
    <div class="add_doctor_cancel_sure">
     <button class="cancel_news_sure add_cancel" @click="back()">取消</button>
     <button class="add_news_sure add_sure" @click="submit()">确定</button>
     </div>
    <div class="clearfix"></div>
    <%--医生编辑取消和确定结束--%>
  </div>
</div>
</div>
</div>
<script src="../../js/sweetalert-dev.js"></script>
<script type="text/javascript">
new Vue({
    el:"#add_news",
    data:{
    deptName:"",
    deptCode:"",
    option:"",
    labelId:"",
    title:"",
    author:"",
    summary:"",
    content:"",
    },
    ready:function(){
    var self = this;
    var news = getHrefParms("add_news");
    self.deptName = news.deptName;
    self.deptCode = news.deptCode;
    self.option = news.option;
    self.labelId = news.labelId;
        $(document).ready(function() {
        $('#editor').summernote({
        height:260,
        lang:'zh-CN',
        callbacks: {
        onImageUpload: function(files) {
        // upload image to server and create imgNode...
        var img = localImg(files[0]);
        }
        }
        });
        });
        function localImg(file) {
        var xmlhttprequest;
        var form = new FormData();
        form.append("file", file);
        if (window.XMLHttpRequest) {
        xmlhttprequest = new XMLHttpRequest();
        if (xmlhttprequest.overrideMimeType) {
        xmlhttprequest.overrideMimeType("text/xml");
        }
        }
        xmlhttprequest.open("POST", "http://cloud.eeesys.com/pu/upload.php", true);
        xmlhttprequest.onreadystatechange = callback.bind(this);
        xmlhttprequest.send(form);
        function callback() {
        if (xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200) {
        var res = JSON.parse(xmlhttprequest.responseText);
        if (res.errcode == 0) {
        $('#editor').summernote('insertImage', res.img);
        } else {
        swal({
        txt: decodeURI(res.errmsg),
        title: "",
        });
        }
        }
        }
        }
    },
    methods:{
    submit:function(){
    var self = this;
    var sHTML = $('.note-editable').html();
    if(self.title==""){
    swal("新闻标题不能为空");
    return;
    }else if(self.title.length>50){
    swal("新闻标题不能大于50字");
    return;
    }
    if(self.author.length>50){
    swal("作者长度不能大于50字");
    return;
    }
    <%--console.log(self.labelId);--%>
    <%--console.log(self.deptCode);--%>
    <%--console.log(self.title);--%>
    <%--console.log(self.author);--%>
    <%--console.log(self.summary);--%>
    <%--console.log(sHTML)--%>
        $.ajax({
        type: 'post',
        url: "add_news.jsp",
        data: {
        act:"add_news",
        deptCode:self.deptCode,
        labelId:self.labelId,
        title:self.title,
        author:self.author,
        summary:self.summary,
        content:encodeURI(sHTML.replace(/"/g, "'")),
        },
        timeout: 3000,
        dataType: 'json',
        success: function(res) {
        if (res.errcode == 0) {
        <%--location.href="news.jsp";--%>
        }
        },
        error: function(error) {
        }
        });
    },
    back:function(){
    locationHerf("news")
    }
    }
    })

</script>

</body>
</html>
